package com.kqb.sgauth.wx.service.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONUtil;
import com.kqb.sgauth.wx.model.constant.WxMiniProgramsUrl;
import com.kqb.sgauth.wx.model.pojo.WxMiniProgramsResult;
import com.kqb.sgauth.wx.model.propertise.JsCode2SessionPropertise;
import com.kqb.sgauth.wx.service.WxMiniProgramsService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.Map;


/**
 * @author 杉果树皮
 */
@Service
public class WxMiniProgramsServiceImpl implements WxMiniProgramsService {

    @Resource
    private JsCode2SessionPropertise jsCode2SessionPropertise;
   
    @Override
    public WxMiniProgramsResult getSessionKey(String code) {
        jsCode2SessionPropertise.setJs_code(code);
        Map<String, Object> requestParams = BeanUtil.beanToMap(jsCode2SessionPropertise);
        String url = WxMiniProgramsUrl.GET_SESSION_KEY + "?" + HttpUtil.toParams(requestParams);
        String req = HttpUtil.get(url);

        return JSONUtil.toBean(req, WxMiniProgramsResult.class);
    }
}
